package com.baseframe.system.feign;

import com.baseframe.system.entity.BasePermission;
import com.baseframe.system.entity.vo.BaseRoleVO;
import com.baseframe.system.service.BasePermissionService;
import com.baseframe.system.service.BaseRoleService;
import com.baseframe.tool.result.R;
import lombok.AllArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@AllArgsConstructor
public class BaseSystemFeignImpl implements BaseSystemFeign {

    private BasePermissionService basePermissionService;
    private BaseRoleService baseRoleService;


    @GetMapping(API+"/find/permissions-by-role-id")
    @Override
    public R<List<BasePermission>> findPermissionListByRoleId(@RequestParam("roleId") Long roleId) {

        List<BasePermission> basePermissionList = basePermissionService.getPermissionsByRoleId(roleId);

        return R.data(basePermissionList);
    }

    /**
     * 根据角色名获取角色id
     * @param roleName 角色名
     * @return
     */
    @GetMapping(API+"/find/role-by-role-name")
    @Override
    public R<BaseRoleVO> findRoleIdByRoleName(@RequestParam("roleName") String roleName) {
         BaseRoleVO baseRoleVO = baseRoleService.findRoleIdByRoleName(roleName);
        return R.data(baseRoleVO);
    }


}
